//
//  ViewController.swift
//  SearchBar属性
//
//  Created by 刘银龙 on 2017/2/13.
//  Copyright © 2017年 Siganet. All rights reserved.
//

import UIKit

class ViewController: UIViewController,UISearchBarDelegate{
    var searchBar:UISearchBar?
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        self.navigationController?.isNavigationBarHidden=false
        initSearchBar()
        initBtn()
        
    }
    
    func initBtn(){
        let btn=UIButton.init(type: .system)
        btn.frame=CGRect(x: 50, y: 200, width: 50, height: 50)
        btn.backgroundColor=UIColor.blue
        btn.addTarget(self, action: #selector(self.btnClicked), for: UIControlEvents.touchUpInside)
        self.view.addSubview(btn)
    }
    
    func btnClicked(){
        let searchVC=SearchBarViewController()
        navigationController?.pushViewController(searchVC, animated: true)
    
    }
    func initSearchBar(){
        searchBar=UISearchBar.init(frame: CGRect(x: 50, y: 50, width: 300, height: 50))
        searchBar?.placeholder="请输入搜索目标"
        self.view.addSubview(searchBar!)
        searchBar?.delegate=self
    }
    func searchBarShouldBeginEditing(_ searchBar: UISearchBar) -> Bool {
       
        return true
    }
    func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
        let searchVC=SearchBarViewController(nibName: "SearchBarViewController", bundle: nil)
        navigationController?.pushViewController(searchVC, animated: true)

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
 /*
    //设置searchBar输入框颜色
    
    searcher​为自己定义的UISearchBar名称
    
    [[[searcher.subviews objectAtIndex:0].subviews objectAtIndex:1] setBackgroundColor:[UIColor greenColor]];
    
    //设置searchBar输入框光标颜色字体颜色及placeholder颜色
    
    
    
    光标颜色：[[[searcher.subviews objectAtIndex:0].subviews objectAtIndex:1] setTintColor:[UIColor greenColor]];
    
    
    
    字体颜色：UITextField *searchField = [searcher valueForKey:@"_searchField"];    searchField.textColor = [UIColor cyanColor];
    
    placeholder颜色：[searchField setValue:[UIColor purpleColor] forKeyPath:@"_placeholderLabel.textColor"];
    
    ​​取消按钮：将cancel修改为“取消”，颜色什么的都可以用这个
    //找到searchbar下得UINavigationButton即是cancel按钮，改变他即可
    
    UIButton *btn = searcher.subviews[0].subviews[2];    [btn setTitle:@"取消" forState:UIControlStateNormal];
    
*/


}

